"use client";
import Title from "antd/es/typography/Title";
import {getQuestionBankVoByPageUsingPost} from "@/api/questionBankController";
import QuestionBankList from "@/components/QuestionBankList";
import "./index.css";
import {useCallback, useEffect, useState} from "react";
import {message} from "antd";

/**
 * 题库列表页面
 * @constructor
 */
export default function BanksPage() {
  const [questionBankList, setQuestionBankList] = useState<
    API.QuestionBankVO[] | []
  >([]); // 状态管理题库信息

  // 题库数量不多，直接全量获取
  const pageSize = 200;

  // 初始化页面数据
  const doInitPage = useCallback(async () => {
    try {
      // 获取题库数据
      const res = await getQuestionBankVoByPageUsingPost({
        pageSize: pageSize,
        sortField: "createTime",
        sortOrder: "descend",
      } as any);
      setQuestionBankList(res.data.records ?? []);
    } catch (e: any) {
      message.error("获取题库列表失败：" + e.message);
    }
  }, []);

  useEffect(() => {
    doInitPage();
  }, [doInitPage]);

  return (
    <div id="banksPage" className="max-width-content">
      <Title level={3}>题库大全</Title>
      <QuestionBankList questionBankList={questionBankList} />
    </div>
  );
}
